﻿using System;
using TMPro;
using UnityEngine.Localization.SmartFormat.Utilities;

namespace Runtime {

    public static class DFR_TMPTextUtilities {

        public static void SetWrapping(TMP_Text text, bool enable) {
#if UNITY_6000_0_OR_NEWER
            text.textWrappingMode = enable ? TextWrappingModes.Normal : TextWrappingModes.NoWrap;
#else
            text.enableWordWrapping = enable;
#endif
        }
    }

    public static class DFR_TimeUtilities {

        public static string GetTimeString(TimeSpan timespan) {
            var options = TimeSpanFormatOptions.Abbreviate;
            var rangeCount = 2;
            if (rangeCount > 0 && timespan.TotalDays > 7) {
                options |= TimeSpanFormatOptions.RangeWeeks;
                rangeCount--;
            }
            if (rangeCount > 0 && timespan.TotalDays > 1) {
                options |= TimeSpanFormatOptions.RangeDays;
                rangeCount--;
            }
            if (rangeCount > 0 && timespan.TotalHours > 1) {
                options |= TimeSpanFormatOptions.RangeHours;
                rangeCount--;
            }
            if (rangeCount > 0 && timespan.TotalMinutes > 1) {
                options |= TimeSpanFormatOptions.RangeMinutes;
                rangeCount--;
            }
            if (rangeCount > 0) {
                options |= TimeSpanFormatOptions.RangeSeconds;
            }
            return DFR_TimeFormatter.ToTimeString(DFR_TimeFormatter.ZH_HANS, timespan, options, DFR_TimeFormatter.ChineseSimplified);
        }
    }
}
